﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using StoragePeriod.Data;
using StoragePeriod.Web.Common;
using StoragePeriod.Common;

namespace StoragePeriod.Web.SysManage
{
    public partial class PanelsList : SecurityPage
    {
        //public override string PrivCode()
        //{
        //    return "Delfault";
        //}

        private void DataBing()
        {
            List<PanelsConfig> list = PanelsConfig.Where("TypeId=@0", Convert.ToInt32(EnumData.PanelsType.实验室使用状态)).OrderBy(p => p.id).ToList();
            this.RepDataList.DataSource = list;
            this.RepDataList.DataBind();
        }

        int i = 0;
        public string GetXH()
        {
            i += 1;
            return i.ToString();
        }

        #region 事件

        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack) return;
            DataBing();
        }

        protected void RepDataList_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "Edit")
            {
                int RawTypeId = Convert.ToInt32(e.CommandArgument);
                this.HidTypeID.Value = RawTypeId.ToString();
                PanelsConfig md=PanelsConfig.Where("id=@0", RawTypeId).First();
                UtilityUI.Load(this.upPanelMain, "LoadData('" + md.title + "','"+md.TestItem+"','"+md.chargePerson+"','"+md.Tel+"','"+md.UseState+"');ShowDlg(1)");
            }
            else
            {
                int RawTypeId = Convert.ToInt32(e.CommandArgument);
                PanelsConfig.Delete("id=@0", RawTypeId);
                DataBing();
                UtilityUI.Load(this.upPanelMain, "alertstr('删除成功！')");
            }
        }

        protected void btPost_Click(object sender, EventArgs e)
        {
            if (this.HidIsEdit.Value == "0")
            {
                //添加
                PanelsConfig md = new PanelsConfig();
                md.TypeId = Convert.ToInt32(EnumData.PanelsType.实验室使用状态);
                md.title = this.txt_Title.Text.Trim();
                md.TestItem = this.txt_TestItem.Text.Trim();
                md.chargePerson = this.txt_chargePerson.Text.Trim();
                md.Tel = this.txt_Tel.Text.Trim();
                md.UseState = this.Drop_UseState.SelectedValue;
                OperationTeam.Insert(md);
                DataBing();
            }
            else
            {
                //修改
                int RawTypeId = Convert.ToInt32(this.HidTypeID.Value);
                PanelsConfig md = PanelsConfig.Where("id=@0", RawTypeId).First();
                md.TypeId = Convert.ToInt32(EnumData.PanelsType.实验室使用状态);
                md.title = this.txt_Title.Text.Trim();
                md.TestItem = this.txt_TestItem.Text.Trim();
                md.chargePerson = this.txt_chargePerson.Text.Trim();
                md.Tel = this.txt_Tel.Text.Trim();
                md.UseState = this.Drop_UseState.SelectedValue;
                PanelsConfig.Update(md, "id=@0", RawTypeId);
                DataBing();
            }
        }

        #endregion
    }
}